package app.common.utils.cjt.ao;

import com.alibaba.fastjson.JSON;
import lombok.Data;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;

/**
 * 其他入库单新建
 * @author feizns
 * @since 2023/3/21
 */
@Data
public class WmsStockinOtherCreateOtherOrderAo {

    private String outer_no;
    private String warehouse_no;
    private String spec_no;
    private String num;

    //货位编号
    private String position_no;

    private Boolean is_check;

    /**
     * 原因
     */
    private String reason;

    /**
     * 生产批号
     */
    private String batch_no;

    /**
     * 生产日期
     */
    private Long production_date;

    /**
     * 备注
     */
    private String remark;

    /**
     * 入库价格
     */
    private BigDecimal stockin_price;

    public Map<String, Object> toMap() {
        Map<String, Object> map = new TreeMap<>();
        map.put("outer_no", outer_no);
        map.put("warehouse_no", warehouse_no);
        map.put("goods_list", Collections.singletonList(toSubMap()));
        map.put("is_check", is_check);
        map.put("reason", reason);
        map.put("remark", remark);
        return map;
    }

    public Map<String, Object> toSubMap() {
        Map<String, Object> map = new TreeMap<>();
        map.put("spec_no", spec_no);
        map.put("num", num);
        map.put("batch_no", batch_no);
        map.put("position_no", position_no);
        if ( production_date != null )
            map.put("production_date", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(production_date)));
        map.put("stockin_price", stockin_price);
        return map;
    }

    public String toData() {
        return JSON.toJSONString(Collections.singletonList(toMap()));
    }
}
